package util

import (
	"regexp"
	"strings"
)

// StringInSlice s是否在ss中，否返回 false，是返回 true
func StringInSlice(s string, ss []string) bool {
	for _, s2 := range ss {
		if s == s2 {
			return true
		}
	}
	return false
}

// Regexp 根据正则比较字符串
func Regexp(s, rege string) bool {
	reg := regexp.MustCompile(rege)
	if reg == nil { //解释失败，返回nil
		return false
	}
	sregx := string(reg.Find([]byte(s)))
	if s == sregx {
		return true
	}
	return false
}

// DeleteBearer 删除token可能存在的‘Bearer’前缀
func DeleteBearer(s string) string {
	if strings.Index(s, "Bearer") != -1 {
		left := strings.TrimLeft(s, "Bearer")
		s = strings.TrimLeft(left, " ")
	}
	return s
}
